﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace List2Code
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class wndList2Code : Window
    {
        public static readonly RoutedUICommand GenerateCode = new RoutedUICommand("Generate Code", "GenerateCode", typeof(wndList2Code));
        public static readonly RoutedUICommand DuplicateTemplate = new RoutedUICommand("DuplicateTemplate", "DuplicateTemplate", typeof(wndList2Code));
        public static readonly RoutedUICommand NewTemplate = new RoutedUICommand("NewTemplate", "NewTemplate", typeof(wndList2Code));
        public static readonly RoutedUICommand SaveTemplate = new RoutedUICommand("SaveTemplate", "SaveTemplate", typeof(wndList2Code));
        public static readonly RoutedUICommand SaveList = new RoutedUICommand("SaveList", "SaveList", typeof(wndList2Code));
        public static readonly RoutedUICommand OpenList = new RoutedUICommand("OpenList", "OpenList", typeof(wndList2Code));

        public wndList2Code()
        {
            InitializeComponent();

            Engine = new List2CodeEngine();

            //Bindings
            CommandBindings.Add(new CommandBinding(GenerateCode,new ExecutedRoutedEventHandler(cmdGenerateCode)));
            CommandBindings.Add(new CommandBinding(DuplicateTemplate, new ExecutedRoutedEventHandler(cmdDuplicateTemplate)));
            CommandBindings.Add(new CommandBinding(NewTemplate, new ExecutedRoutedEventHandler(cmdNewTemplate)));
            CommandBindings.Add(new CommandBinding(SaveTemplate, new ExecutedRoutedEventHandler(cmdSaveTemplate)));
            CommandBindings.Add(new CommandBinding(SaveList, new ExecutedRoutedEventHandler(cmdSaveList)));
            CommandBindings.Add(new CommandBinding(OpenList, new ExecutedRoutedEventHandler(cmdOpenList)));

            //Load Data
            //LoadTemplates();
        }

        public List2CodeEngine Engine { get; set; }

        #region Dependency Properties
        public ObservableCollection<Template> TemplateList
        {
            get { return (ObservableCollection<Template>)GetValue(TemplateListProperty); }
            set { SetValue(TemplateListProperty, value); }
        }

        // Using a DependencyProperty as the backing store for TemplateList.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TemplateListProperty =
            DependencyProperty.Register("TemplateList", typeof(ObservableCollection<Template>), typeof(wndList2Code), new UIPropertyMetadata(null));



        public string ContentList
        {
            get { return (string)GetValue(ContentListProperty); }
            set { SetValue(ContentListProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ContentList.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ContentListProperty =
            DependencyProperty.Register("ContentList", typeof(string), typeof(wndList2Code), new UIPropertyMetadata(""));



        public string Code
        {
            get { return (string)GetValue(CodeProperty); }
            set { SetValue(CodeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Code.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CodeProperty =
            DependencyProperty.Register("Code", typeof(string), typeof(wndList2Code), new UIPropertyMetadata(""));




        public Template SelectedTemplate
        {
            get { return (Template)GetValue(SelectedTemplateProperty); }
            set { SetValue(SelectedTemplateProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SelectedTemplate.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SelectedTemplateProperty =
            DependencyProperty.Register("SelectedTemplate", typeof(Template), typeof(wndList2Code), new UIPropertyMetadata(null));



        public string TemplateText
        {
            get { return (string)GetValue(TemplateTextProperty); }
            set { SetValue(TemplateTextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for TemplateText.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TemplateTextProperty =
            DependencyProperty.Register("TemplateText", typeof(string), typeof(wndList2Code), new UIPropertyMetadata(""));




        #endregion

        #region Public Functions
        public void LoadTemplates()
        {
            TemplateList = new ObservableCollection<Template>();
            TemplateList.Add
                (
                new Template
                {
                    Name = "Property",
                    Category = "C#",
                    Description = "Create Standard Property.",
                    TemplateText = "\\\\Property {0} \r\npublic {0} {1} {get; set;}\r\n"
                }
                );
            ContentList = "string,Person\r\nstring,Surname\r\nint,Age";
        }

        public void SaveTemplates(List<Template> templatecollection)
        {
        }

        
        #endregion

        #region Commands
        protected void cmdGenerateCode(Object sender, ExecutedRoutedEventArgs e)
        {
            Code = Engine.GenerateCode(txtList.Text,txtTemplate.Text);

            TabCode.Focus();
            txtCode.SelectAll();
            txtCode.Copy();
        }

        protected void cmdDuplicateTemplate(Object sender, ExecutedRoutedEventArgs e)
        {
        }

        protected void cmdNewTemplate(Object sender, ExecutedRoutedEventArgs e)
        {
        }

        protected void cmdSaveTemplate(Object sender, ExecutedRoutedEventArgs e)
        {
        }

        protected void cmdSaveList(Object sender, ExecutedRoutedEventArgs e)
        {
        }

        protected void cmdOpenList(Object sender, ExecutedRoutedEventArgs e)
        {
        }

        #endregion


    }
}
